package com.hz.ruoyistorage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hz.ruoyistorage.domain.LgColdStorage;
import com.hz.ruoyistorage.domain.mypojo.LgSubColdSome;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * @version 1.0
 * @Author gj
 * @Date 2025/3/5 9:34
 * @注释
 */
public interface LgColdStorageMapper extends BaseMapper<LgColdStorage> {
    //获得id和名字
    @Select("select cold_id,cold_name from lg_cold_storage")
    public List<Map<String,Object>> getIdAndName();
    @Select("select * from lg_cold_storage where cold_id = #{coldId}")
    public LgColdStorage selectById(Integer coldId);

    //判断是否为空
    @Update({
            "<script>",
            "UPDATE lg_cold_storage",
            "<set>",
            "<if test='coldName != null'>cold_name = #{coldName},</if>",
            "<if test='coldDescript != null'>cold_descript = #{coldDescript},</if>",
            "<if test='address != null'>address = #{address},</if>",
            "<if test='coordinateX != null'>coordinate_x = #{coordinateX},</if>",
            "<if test='coordinateY != null'>coordinate_Y = #{coordinateY},</if>",
            "<if test='area != null'>area = #{area},</if>",
            "<if test='totalVolume != null'>total_volume = #{totalVolume},</if>",
            "<if test='managerId != null'>manager_id = #{managerId},</if>",
            "<if test='status != null'>status = #{status},</if>",
            "</set>",
            "WHERE cold_id = #{coldId}",
            "</script>"
    })
    public int updateById(LgColdStorage lgColdStorage);



    List<LgColdStorage> getReallyList(@Param("coldName") String coldName,
                                      @Param("coldDescript") String coldDescript,
                                      @Param("address") String address,
                                      @Param("area1") String area1,
                                      @Param("area2") String area2,
                                      @Param("totalVolume1") String totalVolume1,
                                      @Param("totalVolume2") String totalVolume2,
                                      @Param("managerId") Integer managerId,
                                      @Param("status") Integer status,
                                      @Param("firstNum") Integer firstNum,
                                      @Param("secondNum") Integer secondNum,
                                      @Param("createBy") String createBy);

    int getCount(@Param("coldName") String coldName,
                 @Param("coldDescript") String coldDescript,
                 @Param("address") String address,
                 @Param("area1") String area1,
                 @Param("area2") String area2,
                 @Param("totalVolume1") String totalVolume1,
                 @Param("totalVolume2") String totalVolume2,
                 @Param("managerId") Integer managerId,
                 @Param("status") Integer status,
                 @Param("createBy") String createBy);



    @Select("select user_name from sys_user where user_id = #{userId}")
    public String getUserName(Integer userId);


    public  List<LgColdStorage> getAllByManagerId(Integer managerId);

    public List<LgColdStorage> getColdAndMachine(@Param("coldName") String coldName,
                                                 @Param("coldDescript") String coldDescript,
                                                 @Param("address") String address,
                                                 @Param("area1") String area1,
                                                 @Param("area2") String area2,
                                                 @Param("totalVolume1") String totalVolume1,
                                                 @Param("totalVolume2") String totalVolume2,
                                                 @Param("managerId") Integer managerId,
                                                 @Param("status") Integer status,
                                                 @Param("firstNum") Integer firstNum,
                                                 @Param("secondNum") Integer secondNum);

    @Update("update lg_cold_storage set remaining_volume = #{remainingVolume} where cold_id = #{coldId}")
    public void updateCold(@Param("remainingVolume") Double remainingVolume,@Param("coldId") Integer coldId);
}
